//
//  main.c
//  C_6结构联合和位字段
//
//  Created by Robin on 16/3/17.
//  Copyright © 2016年 cnbm. All rights reserved.
//

#include <stdio.h>

typedef enum {
    COUNT,
    POUNDS,
    PINTS
}unit_of_measure;

typedef union {
    int count;
    float volume;
    float weight;
}quantity;

typedef struct {
    const char *name;
    const char *country;
    quantity amount;
    unit_of_measure unit;
}friut_order;

// 位字段
typedef struct {
    unsigned int first_visit:1;
    unsigned int come_again:1;
    unsigned int fingers_losts:4;
    unsigned int shark_attack:1;
    unsigned int days_a_week:3;
}synth;

void display (friut_order *t);

int main(int argc, const char * argv[]) {
    

    friut_order apples = {"apple","England",.amount.count=144,COUNT};
    friut_order strawberries = {"strawberries",.amount.weight=130.9,POUNDS};
    friut_order oj = {"organ",.amount.volume=10,PINTS};
    
    puts("this order contains :");

    display(&apples);
    display(&strawberries);
    display(&oj);
    
    return 0;
}

void display (friut_order *t){
    
    switch (t->unit) {
        case PINTS:
            printf("%f pints of %s\n",t->amount.volume,t->name);
            break;
        case POUNDS:
            printf("%f pounds of %s\n",t->amount.weight,t->name);
            break;
        case COUNT:
            printf("%i lbs of %s\n",t->amount.count,t->name);
            break;
        default:
            break;
    }
}

